/*********************************************************************
*                                                                    *
*                SEGGER Microcontroller GmbH & Co. KG                *
*        Solutions for real time microcontroller applications        *
*                                                                    *
**********************************************************************
*                                                                    *
* C-file generated by:                                               *
*                                                                    *
*        GUI_Builder for emWin version 5.40                          *
*        Compiled Jun 22 2017, 10:13:26                              *
*        (c) 2017 Segger Microcontroller GmbH & Co. KG               *
*                                                                    *
**********************************************************************
*                                                                    *
*        Internet: www.segger.com  Support: support@segger.com       *
*                                                                    *
**********************************************************************
*/

// USER START (Optionally insert additional includes)
// USER END

#include "DIALOG.h"
#include "stdlib.h"
/*********************************************************************
*
*       Defines
*
**********************************************************************
*/
#define ID_WINDOW_0      (GUI_ID_USER + 0x10)
#define ID_GRAPH_0      (GUI_ID_USER + 0x13)
#define ID_HEADER_0      (GUI_ID_USER + 0x14)


// USER START (Optionally insert additional defines)
// USER END

/*********************************************************************
*
*       Static data
*
**********************************************************************
*/

// USER START (Optionally insert additional static data)
static GRAPH_SCALE_Handle hScaleV; //--------------（1）
static GRAPH_DATA_Handle ahData;
// USER END

/*********************************************************************
*
*       _aDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] =
{
    { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 400, 240, 0, 0x0, 0 },
    { GRAPH_CreateIndirect, "Graph", ID_GRAPH_0, 17, 48, 362, 151, 0, 0x0, 0 },
    { HEADER_CreateIndirect, "Header", ID_HEADER_0, 0, 0, 400, 23, 0, 0x0, 0 },
    // USER START (Optionally insert additional widgets)
    // USER END
};

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/

// USER START (Optionally insert additional static code)
// USER END

/*********************************************************************
*
*       _cbDialog
*/
static void _cbDialog(WM_MESSAGE *pMsg)
{
    WM_HWIN hItem;
    int     NCode;
    int     Id;
    // USER START (Optionally insert additional variables)
    // USER END

    switch (pMsg->MsgId)
    {
    case WM_INIT_DIALOG:
        //
        // Initialization of 'Header'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_HEADER_0);
        HEADER_AddItem(hItem, 40, "Time", 14);
        // USER START (Optionally insert additional code for further widget initialization)
        hItem = WM_GetDialogItem(pMsg->hWin, ID_GRAPH_0); //--------------（3）
        /* 创建数据对象 ***********************/
        ahData = GRAPH_DATA_YT_Create(GUI_GREEN, 400, 0, 0); //--------------（4）
        /* 数据对象添加到图形控件 */
        GRAPH_AttachData(hItem, ahData); //--------------（5）
        /* 设置 Y 轴方向的栅格间距 */
        GRAPH_SetGridDistY(hItem, 20); //--------------（6）
        /* 固定 X 轴方向的栅格 */
        GRAPH_SetGridFixedX(hItem, 1); //--------------（7） /* 设置栅格可见 */
        GRAPH_SetGridVis(hItem, 1); //--------------（8）
        /* 创建刻度对象 ********************/
        hScaleV = GRAPH_SCALE_Create( 20, GUI_TA_RIGHT, GRAPH_SCALE_CF_VERTICAL, 20); //--------------（9）
        /* 将垂直刻度对象添加到图形控件 */
        GRAPH_AttachScale(hItem, hScaleV); //--------------（10）
        /* 用于设置比例刻度的因子 */
        GRAPH_SCALE_SetFactor(hScaleV, 0.5); //--------------（11）
        /* 设置标签字体颜色 */
        GRAPH_SCALE_SetTextColor(hScaleV, GUI_RED); //--------------（12）
        /* 设置上下左右边界的大小 */
        GRAPH_SetBorder(hItem, 20, 10, 10, 10); //--------------（13）
        // USER END
        break;
    /* 定时器消息 */
    case WM_TIMER: //--------------（1）
        /* 每 50ms 给绘图控件添加一次新的数据 */
        GRAPH_DATA_YT_AddValue(ahData, rand() % 100); //--------------（14）
        WM_RestartTimer(pMsg->Data.v, 100);
        break;
    case WM_NOTIFY_PARENT:
        Id    = WM_GetId(pMsg->hWinSrc);
        NCode = pMsg->Data.v;
        switch (Id)
        {
        case ID_HEADER_0: // Notifications sent by 'Header'
            switch (NCode)
            {
            case WM_NOTIFICATION_CLICKED:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
            case WM_NOTIFICATION_RELEASED:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
            case WM_NOTIFICATION_MOVED_OUT:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
                // USER START (Optionally insert additional code for further notification handling)
                // USER END
            }
            break;
            // USER START (Optionally insert additional code for further Ids)
            // USER END
        }
        break;
    // USER START (Optionally insert additional message handling)
    // USER END
    default:
        WM_DefaultProc(pMsg);
        break;
    }
}

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       CreateWindow
*/
WM_HWIN CreateWindow(void);
WM_HWIN CreateWindow(void)
{
    WM_HWIN hWin;

    hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
    return hWin;
}
GUI_HWIN initGraph(GUI_HWIN father, int x, int y)
{
    WM_HWIN hGraphWin;
    volatile WM_HTIMER hTimer; // 防止编译器优化，确保每次获取内存数据
    hGraphWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, father, x, y);
    /* 给对话框 hDlg 创建定时器，溢出时间是 100ms */
    hTimer = WM_CreateTimer(WM_GetClientWindow(hGraphWin), 0, 100, 0); //--------------（2）
    return hGraphWin;
}
// USER START (Optionally insert additional public code)
// USER END

/*************************** End of file ****************************/
